package lzg.blog.config.application;
import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

@Configuration
@PropertySource("application.properties")
public class RedisApplication {

    @Value("${spring.redis.host}")
    String address;

    @Value("${spring.redis.port}")
    String port;

    @Value("${spring.redis.password}")
    String password;

    @Bean(destroyMethod = "shutdown")
    public RedissonClient redisson() {
        Config config = new Config();

        // 集群模式 config.useClusterServers()
        // 单节点模式
        config.useSingleServer()
                .setConnectTimeout(10000)  // 10秒连接超时
                .setRetryAttempts(3)       // 重试3次
                .setRetryInterval(1500)   // 重试间隔1.5秒:ml-citation{ref="3,6" data="citationList"}
                .setAddress(address + ":" + port) // Redis服务器地址
                .setPassword(password); // 如果你的Redis设置了密码，则需要配置密码
        return Redisson.create(config);
    }

}
